package mid;

import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.Map;

public class a3_无重复字符的最长子串 {
    public int lengthOfLongestSubstring(String s) {
        if (s.length() == 0) {
            return 0;
        }
        int start = 0;
        int max = 0;
        char[] chars = s.toCharArray();
        Map<Character,Integer> map = new HashMap<>();
        for (int i = 0; i < s.toCharArray().length; i++) {
            if (map.containsKey(chars[i])) {
                start=Math.max(start,map.get(chars[i]));
            } else {
                map.put(chars[i],i+1);
                max=Math.max(i-start+1,max);
            }
        }
        return max;

    }

}
